<template>
    <el-dialog :title="'重置密码'"  :visible.sync="realshow"
  @close="hideRN"
  append-to-body
  top="25vh"
  >
  <el-form ref="form2" label-width="120px" :model="RealNameinfo" label-position="left"  >
  <el-form-item label="真实姓名" >
     <el-input placeholder="请输真实姓名"
      v-model="RealNameinfo.realName"
      
      ></el-input>
  </el-form-item>
  <el-form-item label="用户身份id">
  <el-input
   placeholder="用户身份证id"
    v-model="RealNameinfo.idCardNo"
    
    ></el-input>
  </el-form-item>
    <el-form-item label="用户身份凭证相片-正面">
      <!-- <el-input placeholder="再次输入密码" v-model="RealNameinfo.idCardFront"></el-input> -->
      <el-upload
        ref="frontup"
        action="/api/file/upload"
        :file-list="fileListfront"
        :headers="{Authorization:token}"
        :limit="1"
        :multiple="false"
        list-type="picture"
        :on-success="frontup"
        :on-remove="frontClc"
        
        >
        <el-button size="small" type="primary">点击上传</el-button>
      </el-upload>
    </el-form-item>
    <el-form-item label="用户身份凭证相片-反面">
    <!-- <el-input placeholder="再次输入密码" v-model="RealNameinfo.idCardOpposite"></el-input> -->
      <el-upload
        ref="backup"
        action="/api/file/upload"
        :file-list="fileList"
        :headers="{Authorization:token}"
        :limit="1"
        :multiple="false"
        list-type="picture"
        :on-success="backup"
        :on-remove="backClc"
        >
        <el-button size="small" type="primary">点击上传</el-button>
      </el-upload>
  </el-form-item>

</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary"  :disabled="disabled" @click="insertAuth" class="confirm">确 定</el-button>
</div>
</el-dialog>
</template>

<script>
import {insertAuthentication,} from "@/Util/request.js"
export default {
  data(){
    return{
      RealNameShow:false,
      RealNameinfo:{
        realName:"",
        idCardNo:null,
        idCardFront:"",
        idCardOpposite:"",
       
      },
      realshow:false,
      token:localStorage.getItem("token"),
      fileListfront:[],
      fileList:[],
      disabled:true
      
    }

  },
  props:{
     userinfo:Object,
     showpop:Boolean,
     realdata:Object
  },
  mounted(){
    // agentRealinfo((res)=>{

    // },{
    //   uid:this.userinfo.uid
    // })
    console.log("启动了");
  },

  methods:{
    hideRN(){
      this.$emit("close")
         this.RealNameinfo={
        realName:"",
        idCardNo:null,
        idCardFront:"",
        idCardOpposite:""
      }
      this.$emit("refresh")
      this.$refs.frontup.clearFiles()
      this.$refs.backup.clearFiles()
    },
    frontup(res,file,filelist){
      // console.log(res,"||||",file,"\\\\",filelist);
      if(res.code ==200){
       this.RealNameinfo.idCardFront = res.data
      }
    },
    frontClc(file,filelist){
     this.RealNameinfo.idCardFront=null
    },
    backup(res,file,filelist){
      // console.log(res,"||||",file,"\\\\",filelist);
      if(res.code ==200){
        this.RealNameinfo.idCardOpposite = res.data
      }
    },
    backClc(){
      this.RealNameinfo.idCardOpposite = ""
    },
    insertAuth(){
      insertAuthentication((res)=>{
        console.log(res);
        if(res.code==200){
            this.hideRN()
        }
      },{
        ...this.RealNameinfo,
        uid:this.userinfo.uid
      })
    }


  },
  watch:{
    showpop(){
      this.realshow=this.showpop
    },
    RealNameinfo:{
      handler(n,o){
        for(let i in n){
          if(!n[i]){
            this.disabled =true
            return
          }else{
            this.disabled=false
          }
        }
      },
      deep:true
    },
    realdata:{
      deep:true,
      handler(n,o){
        if(n.idCardFront){
                this.fileListfront=[{
          name:"身份证正面",
          url:n.idCardFront
        }]
        }
        if(n.idCardOpposite){
                  this.fileList=[{
          name:"身份证背面",
          url:n.idCardOpposite
        }]
        }
        this.RealNameinfo.realName=n.realName
        this.RealNameinfo.idCardNo=n.idCardNo
     }
    }
  }
}
</script>

<style lang="less" scoped>

</style>